home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / lollipop / extern.tex < prev    next >
Text File  |  1993-01-28  |  15KB  |  389 lines

  1. % Extern.tex copyright 1992 Victor Eijkhout
  2. %
  3. \Chapter[chap:referencing]
  4. Referencing
  5.  
  6. In manuals and scientific documents you often want to write something
  7. like `see Chapter~4'. But what if you shuffle the chapters a bit? It
  8. would be nice if the number would be updated automatically. With
  9. \Lollipop, as with many other \TeX\ macro packages, this is easily
  10. done.
  11.  
  12. Here is an example to set the mood for the rest of this chapter.
  13. The sort of thing that is referred to most is a heading. So suppose
  14. you want to refer to a section number.
  15.  
  16. \Example
  17. \DefineHeading:TestSection
  18.  line:start Style:italic TestSectionCounter Spaces:2 title
  19.  line:stop Stop
  20. \TestSection[one:section?] First section\par
  21. After this section will come section~\ref[other:section!].
  22.  
  23. \TestSection[other:section!] Another section\par
  24. This is the section that came after section~\ref[one:section?].
  25. \ExampleStop
  26.  
  27. \Section What and how do you reference?
  28.  
  29. You can reference not only headings but everything that has a
  30. counter. Thus all generic constructs can be referenced, and in
  31. addition you can reference item numbers in a list (there are examples
  32. of this latter possibility in section~\ref[sec:bib]). The simplest way
  33. of referencing something is to put the key in square brackets behind
  34. it:
  35.  
  36. \Ver>\Section[this:section] The title of This Section<Rev
  37. You can then reference the key by \refcs{ref}, or the page
  38. where it appeared by~\refcs{pgref}:
  39. \Ver>Section \ref[this:section] on page \pgref[this:section]<Rev
  40.  
  41. As you may have guessed from the above examples, keys can contain all
  42. sorts of characters. Only brackets, braces, and the hash sign are
  43. excepted. You get an error message if you try to use the same key
  44. twice.
  45.  
  46. Another way of declaring a key is to use the command \refcs{label}
  47. carrying the key
  48. \Ver>\label[the:key]<Rev
  49. This can be useful if you want to declare two keys for a single
  50. reference. Make sure that the \cs{label} command is not part of the
  51. title. Unexplained phenomena occur if you do that. Instead put the
  52. label after the construct you want to reference:
  53. \Ver>\Section Precautions and remedies
  54.  
  55. \label[sec:precautions]\label[sec:remedies]
  56. In this section ...<Rev
  57.  
  58. \Section[sec:shape:reference] The shape of the reference
  59.  
  60. By default, a reference consists of just the number of the thing you
  61. reference. There are two ways in which you can change this, one
  62. systematic, and one on-the-fly.
  63.  
  64. \SubSection Defining the shape of the reference
  65.  
  66. You can customize the way an object is
  67. referenced by using the option \refopt{label} in its definition. For
  68. instance, often you want things like parentheses around references.
  69. Putting this information in the label definition saves you a lot of
  70. work in case you change your mind later.
  71.  
  72. \Example
  73. \DefineHeading:TestSection
  74.  line:start Style:italic TestSectionCounter Spaces:2 title line:stop
  75.  label:start ( TestSectionCounter ) label:stop Stop
  76. \TestSection[one:section?2] First section\par
  77. After this section will come section~\ref[other:section!2].
  78.  
  79. \TestSection[other:section!2] Another section\par
  80. This is the section that came after section~\ref[one:section?2].
  81. \ExampleStop
  82.  
  83. Another use of customized labels is including other counters in the
  84. reference:
  85.  
  86. \Example
  87. \DefineHeading:TestChapter 
  88.  line:start Style:bold TestChapterCounter / title line:stop Stop
  89. \DefineHeading:TestSection
  90.  line:start Style:italic TestSectionCounter Spaces:2 title line:stop
  91.  label:start TestChapterCounter . 
  92.              TestSectionCounter label:stop Stop
  93. \TestChapter First chapter\par
  94. Pretty short chapter
  95. \TestChapter Second chapter\par
  96. \TestSection[one:section?3] First section\par
  97. After this section will come section~\ref[other:section!3].
  98.  
  99. \TestSection[other:section!3] Another section\par
  100. This is the section that came after section~\ref[one:section?3].
  101. \ExampleStop
  102.  
  103. A more surprising application of explicit definition of labels is
  104. inclusion of the title in the reference.
  105. \Example
  106. \DefineHeading:TestSection
  107.  line:start Style:italic TestSectionCounter Spaces:2 title line:stop 
  108.  label:start TestSectionCounter literal: Spaces:1 
  109.              Style:italic title label:stop Stop
  110. \TestSection[one:section?4] First section\par
  111. After this section will come section~\ref[other:section!4].
  112.  
  113. \TestSection[other:section!4] Another section\par
  114. This is the section that came after section~\ref[one:section?4].
  115. \ExampleStop
  116.  
  117. \SubSection[sec:exp-ref] Explicit specification of the reference
  118.  
  119. For every specific object referenced you can specify the reference by
  120. using an optional argument before the label key. Have a look at the
  121. next example.
  122.  
  123. \Example
  124. \DefineHeading:TestSection counter:A
  125.  line:start Style:bold TestSectionCounter . Spaces:2 title line:stop
  126.  Stop
  127. \TestSection[ref:one] Lalala\par
  128. This is before section \ref[ref:two].
  129. \TestSection<`the Didi section'>[ref:two] Dididi\par
  130. This is after section \ref[ref:one].
  131. \ExampleStop
  132.  
  133. This mechanism is also used in lists, where it's mostly useful for
  134. bibliographies generated by Bib\TeX; see section~\ref[sec:BibTeX].
  135.  
  136. \Section[sec:ref-local] Local references
  137.  
  138. Some documents are
  139. collated out of parts that were documents in themselves. 
  140. The \Lollipop\ command \cs{InputFile} facilitates in a number
  141. of ways working with such a segmented file (see
  142. section~\ref[sec:InputFile]). One of the problems with input files is
  143. that in such a case it may happen that the same reference key is used
  144. in more than one part of the document. This phenomenon is
  145. not at all unknown in multiple authored documents. Ordinarily this
  146. would result in incorrect references.
  147.  
  148. To prevent such collisions \Lollipop\ can use local
  149. references: the command \refcs{LocalReferences} has default \n{no},
  150. and specifying 
  151. \Ver>LocalReferences:yes<Rev
  152. creates local \file{aux} files for each input file.
  153.  
  154. \Section[sec:bib] Bibliography citations
  155.  
  156. \Lollipop\ has an interface to Bib\TeX. However, since a bibliography
  157. is just a list, referencing items in it is quite easy, even if you
  158. don't use Bib\TeX.
  159.  
  160. \SubSection Bibliographies without Bib\TeX
  161.  
  162. This section doesn't tell you anything that cannot be found elsewhere
  163. in this manual. The following two examples define a bibliography as
  164. just a list, and by giving labels to the items you can refer to them.
  165.  
  166. \Example
  167. \DefineList:BibList item:left [ itemCounter ] item:stop
  168.  label:start [ itemCounter ] label:stop Stop
  169. In this example we shall have occasion to refer to 
  170. \ref[Abee80] and~\ref[Ceede79].\par
  171. \Indent:no Bibliography
  172. \BibList \item[Ace55] C.D. Ace, Inscrutible title.
  173. \item[Abee80] E.F. Abee, Worthless drivel.
  174. \item[Ceede79] G.H. Ceede, Contractual obligation.
  175. \>
  176. \ExampleStop
  177.  
  178. Here is a way to customize the label (if you need to refresh your
  179. memory about description lists, see
  180. section~\ref[sec:description:list]).
  181.  
  182. \Example
  183. \DefineList:BibList item:left [ itemCounter ] item:stop
  184.  label:start ( description ) label:stop Stop
  185. In this example we shall have occasion to refer to 
  186. \ref[Abe80] and~\ref[Ceedee79].\par
  187. \Indent:no Bibliography
  188. \BibList \item[Aace55] Aace55
  189. C.D. Aace, Inscrutible title.
  190. \item[Abe80] Abe80
  191. E.F. Abe, Worthless drivel.
  192. \item[Ceedee79] Ceedee79
  193. G.H. Ceedee, Contractual obligation.
  194. \>
  195. \ExampleStop
  196.  
  197. \SubSection[sec:BibTeX] Bibliographies with Bib\TeX
  198.  
  199. \Lollipop has  an interface to the popular Bib\TeX\
  200. bibliography database program, based on the `BtxMac' macros
  201. by Karl Berry and Oren Patashnik. \Lollipop\ is set up for them, you
  202. only have to \cs{input} the file \file{btxmac.tex}. (The version
  203. of btxmac used to test this is \n{0.99h}.) You can find global
  204. information about Bib\TeX\ in the \LaTeX\ book~{%\tracingmacros=2
  205. %\tracingcommands\tracingmacros 
  206. \bibref[La:book]},
  207. since Bib\TeX\ was
  208. originally written for \LaTeX.
  209.  
  210. Since there is some redefining going on between btxmac and \Lollipop\
  211. you have to load the btxmac file before the \cs{Start} command (see
  212. section~\ref[sec:doc-start-stop]).
  213.  
  214. Since the btxmac file already has a default way of formatting the
  215. bibliography you can get away with just putting the lines
  216.  \Ver>\bibliography{ <bfile> }
  217. \bibliographystyle{ <bstyle> }<Rev
  218.  in your file wherever you want the bibliography.
  219.  
  220. If you want to define your own bibliography, you have to use
  221. \refcs{DefineBBL} which is practically a synonym for
  222. \ver>\DefineList:BBL>, so you can see in the `lists' chapter of this
  223. manual what options apply.
  224.  
  225. For example:
  226.  \Ver>\DefineBBL line:start Style:italic literal:Literature line:stop
  227.   item:left [ begingroup Style:bold itemCounter 
  228.             endgroup ] item:stop
  229.  Stop<Rev
  230.  
  231. You refer to a bibliography item by \refcs{bibref}, as in
  232. \ver>\bibref[Knuth80]>. This command has a very simple definition
  233.  \Ver>\def\bibref[#1]{[\ref[#1]]\nocite{#1}}<Rev
  234. so you can easily redefine it. For instance
  235.  \Ver>\def\supref[#1]{$^{\rm \ref[#1]}$\nocite{#1}}<Rev
  236.  will make your references into superscripts.
  237. Make sure that
  238. the call to \cs{nocite} appears, because that generates the request for
  239. Bib\TeX.
  240.  
  241. The \Lollipop\ command \ver>\WriteExtern:no> (see
  242. section~\ref[sec:write-extern]) defines \cs{noauxfile} to prevent
  243. regeneration of the bib entries in the \file{.aux} file. 
  244. You don't have to do that anymore.
  245.  
  246. \Chapter[chap:external-files] External Files
  247.  
  248. Some document require information to be collected during a run. Such
  249. information typically is a table of contents or index, and it is
  250. gathered in an external file. (The reason for gathering such
  251. information in a file at all is that often some external manipulation,
  252. for instance sorting of an index, is needed.) Since there are many
  253. possibilities for external files (mathematical monographs may have a
  254. list of definitions, or a list of notations) \Lollipop\ does not
  255. predefine such files, but supplies all of the tools for creating them.
  256.  
  257. External files involve four actions: 
  258. \Enumerate\item The file should be declared.
  259. \item It should be specified what information is to be written to the
  260. file.
  261. \item The formatting of the contents of the file has to be specified.
  262. \item The file has to be loaded.
  263. \>
  264.  
  265. You can have at most 15 external files per document.
  266.  
  267. \Section[sec:write-extern] Declaring and loading an external file
  268.  
  269. The first act, declaring the existence of the external file is very
  270. easy with the command \refcs{DefineExternalFile}:
  271.  an internal name and a three-character file name extension have
  272. to be given as parameters.
  273. \Ver>\DefineExternalFile:contents=toc<Rev
  274. With this definition, if the document is called \file{book.tex} then
  275. the `contents' will be gathered in a file called \file{book.toc}.
  276.  
  277. For each external file \n{Foo} there is a command to determine whether
  278. that file will be regenerated in the next run of \TeX:
  279. \refcs{WriteFoo} with values \n{yes}/\n{no} will allow or prevent the
  280. file being regenerated. The value \opt{yes} is default. The
  281. command \refcs{WriteExtern} (values \n{yes}/\n{no})
  282. can be used to prevent writing out any external files (including the
  283. \file{.aux} file that keeps track of references).
  284.  
  285. The final act, loading an external file, is as easy as declaring it:
  286. use \refcs{LoadExternalFile} as in
  287. \Ver>\LoadExternalFile:contents<Rev
  288. This does not cause any page breaks or headings to be set over the
  289. loaded material, so you have to do that explicitly.
  290.  
  291. \Section[sec:ext-option] Generating external files
  292.  
  293. Next, macros that write to the table of contents have to declare this
  294. information. The \refopt{external} option is used for this.
  295. Any counter that the construct has will be written out
  296. automatically, and the style designer usually has to specify only
  297. that the title will be written out.
  298. \Ver>\DefineHeading:Section
  299.     [...]
  300.     external:contents title external:stop<Rev
  301.  
  302. There is no objection to a construct writing information to more than
  303. one external file.
  304.  
  305. You can write arbitrary information to an external file, if you see a
  306. reason to do so, by \refcs{ToExternalFile}, which takes a file name
  307. and an text argument. The example below has an instance of this
  308. command.
  309.  
  310. \Section[sec:ext-item] Formatting an external file
  311.  
  312. The hardest part is declaring the formatting of an external file. For
  313. this a separate generic construct exists: the `external item' with
  314. defining command \refcs{DefineExternalItem}. For example, if
  315. \cs{Section} writes to \n{contents}, than an external item \n{Section}
  316. corresponding to this file has to be declared. The option
  317. \refopt{file} is use to declare to which file the external item
  318. belongs. This way the same name can be reused for more than one file.
  319.  
  320. \Ver>\DefineExternalItem:Section file:contents
  321.     [...] Stop<Rev
  322.  
  323. An external item is basically a list with just one item. Thus, the
  324. option \refopt{item} is available. The elements of an external item are
  325. the label (the counter value), the page number where the information
  326. was generated, and the title. 
  327. For the label (say for a construct \cs{Foo})
  328. an option \refopt{FooLabel} is created.
  329. Thus the typical formating looks like
  330. \Ver>\DefineExternalItem:Chapter file:contents
  331.     item:left ChapterLabel item:stop
  332.     title begingroup Spaces:2 Style:italic Page endgroup
  333.     Stop<Rev
  334. In fact, a control sequence \refcs{FooLabel} is created, which
  335. can be used in other external items.
  336.  
  337. Since an external item is a list in itself, you have to pull a
  338. certain trick to get items for subsections to indent further than
  339. those for sections. This is what the command \cs{PushIndentLevel} was
  340. designed for.
  341.  
  342. A typical indented item looks like:
  343. \Ver>\DefineExternalItem:SubSection file:contents
  344.     PushIndentLevel PushIndentLevel
  345.     item:left SectionLabel . SubSectionLabel item:stop
  346.     title begingroup Spaces:2 Style:italic Page endgroup
  347.     Stop<Rev
  348.  
  349. \Section Example
  350.  
  351. The following example is for a typical table of contents that
  352. records sections and subsections. In good old-fashioned style, the
  353. subsections are indented with respect to the sections.
  354.  
  355. \Example
  356. \DefineExternalFile:TheContents=tct
  357. \DefineHeading:TestChapter Style:bold
  358.  line:start TestChapterCounter Spaces:2 title line:stop
  359.  external:TheContents title external:stop Stop
  360. \DefineExternalItem:TestChapter file:TheContents
  361.  item:left Style:bold TestChapterLabel item:stop title white:5pt
  362.       Page par Stop
  363. \DefineHeading:TestSection Style:italic
  364.  line:start TestChapterCounter . TestSectionCounter 
  365.             Spaces:2 title line:stop
  366.  external:TheContents title external:stop Stop
  367. \GoverningCounter:TestSection=TestChapter
  368. \DefineExternalItem:TestSection file:TheContents PushIndentLevel
  369.  item:left Style:bold TestChapterLabel . TestSectionLabel item:stop 
  370.  title white:5pt Page par Stop
  371.  
  372. \LoadExternalFile:TheContents
  373. \TestChapter First heading\par
  374. \TestSection First subheading\par
  375. Some text might be nice.
  376. \TestSection Second subheading\par
  377. Some more text.
  378. %\ToExternalFile:TheContents={Enclosed Graphics}
  379. \TestChapter Second heading\par
  380. \TestSection Third subheading\par
  381. Yet more text.
  382. \TestSection Fourth subheading\par
  383. And again: text.
  384. \ExampleStop
  385.  
  386. \endinput
  387.  
  388. 92/11/26 BibTeX section
  389.